// 全局变量
var MY_SM_SEWAGE_TEST_REPORT = (function() {

	// 收集页面查询参数
	function getParams(){
		
		var data = {};
		// 异常状态
//		var registryStatus =  $('#registryStatus').val();
//		if ( registryStatus != '-1' ){
//			data.registryStatus = registryStatus;
//		}
		// 分类1：消毒器械检测 2：污水余氯日常检测 3：医疗污水检测报告
		// data.dateYm = $('#year').val() + '' + $('#month').val();
		data.dtFrom = $('#dtFrom').val();
		data.dtTo = $('#dtTo').val();
		data.institutionId = $('#institutionId').val();
		data.businessSubType = $('#test_sec').find('select[name="businessSubType"]').val();
		
		return data;
	}

	// add by zhengxb 2019.6.21  end ---------------------------------------------------------
	return {
		getParams:getParams
	}
})();

$(document).ready(function() {
	// 显示图片
	$('#test_report_tbody').on('click','button[name="showImage"]',function(){
		var $that = $(this).closest('tr');
		$('#imageModalTitle').text($that.data('institution_name'));
		MY_SHOW_IMG.createShowImgModal($that.data('institution_id'),$that.data('report_img_id'));
	});
	
	// 显示申诉图片
	$('#test_report_tbody').on('click','button[name="showAppealAtta"]',function(){
		var $that = $(this);
		var $parentTr = $that.closest('tr');
		
		var appealAtta = $parentTr.data('appeal_atta');
		var institutionId = $('#institutionId').val();
		// 显示交接单图片
		MY_SHOW_IMG.createShowImgModal(institutionId ,appealAtta);
	});
	
	// 业务下拉框变化时
	$('#test_sec').find('select[name="businessSubType"]').on('change',function(){
		var $thead = $('#test_report_thead');
	    var $tbody = $('#test_report_tbody');
		var businessSubType = $('#test_sec').find('select[name="businessSubType"]').val();
        if ( businessSubType == 301 || businessSubType == 303  ){//医疗污水检测报告
    		var params = MY_SM_SEWAGE_TEST_REPORT.getParams();
    		MY_SEWAGE_TEST_REPORT_COM.loadItem(params,$thead,$tbody);
        } else  if ( businessSubType == 302 ){//污水余氯日常检测
    		var params = MY_SM_SEWAGE.getDetailParams();
    		MY_SEWAGE_COM.loadDetailItem(params,$thead,$tbody);
        } 
	});
	
	// 文件下载
	$('#test_report_tbody').on('click','button[name="download"]',function(){
		var $that = $(this);
		var $parent = $that.closest('tr');
    	
    	var data = {};
    	data.reportImgId = $parent.data('report_img_id');
    	data.institutionId = $parent.data('institution_id');
    	data.destFileName = '检测报告';
    	
    	var url = 'invs_multipleDownLoad.do';
    	
    	WeKnow.loading();
    	$.fileDownload(url,
    		{
            httpMethod: 'POST',
            data: data,
            prepareCallback:function(url){
            	console.log('download start')
            	WeKnow.loading();
            },
            successCallback:function(url){
            	console.log('download end')
            	WeKnow.closeLoading();
            },
            failCallback: function (html, url) {
            	WeKnow.errorMsg('下载失败');
            }
         });
	});
	
	// 处理申诉 OR 取消异常   注：申诉处理由于多个页面共用，故提炼成appeal.js
	$('tbody#test_report_tbody').on('click','button[name="check"],button[name="closeIllegal"]',function(){
		var $that = $(this);
		var $parentTr = $that.closest('tr');
		
		var illegalId = $parentTr.data('illegal_id');
		var originBtnName= $that.prop('name');
		
		var $thead = $('#test_report_thead');
	    var $tbody = $('#test_report_tbody');
	    var businessSubType = $('#test_sec').find('select[name="businessSubType"]').val();
		if ( businessSubType == 301 || businessSubType == 303  ){//医疗污水检测报告
    		var params = MY_SM_SEWAGE_TEST_REPORT.getParams();
    		// 更新用模态框
    		MY_APPEAL.createModalWin
    			(illegalId,originBtnName,
    				function(){ MY_SEWAGE_TEST_REPORT_COM.loadItem(params,$thead,$tbody);},
    				function(){ MY_SUMMARIZE.getSummarize();}
    			);
    		
    		MY_SEWAGE_TEST_REPORT_COM.loadItem(params,$thead,$tbody);
        } else  if ( businessSubType == 302 ){//污水余氯日常检测
    		var params = MY_SM_SEWAGE.getDetailParams();
    		// 更新用模态框
    		MY_APPEAL.createModalWin
    			(illegalId,originBtnName,
    				function(){ MY_SEWAGE_COM.loadDetailItem(params,$thead,$tbody);},
    				function(){ MY_SUMMARIZE.getSummarize();}
    			);
        } 
		
		
	});
});